package org.vectrics.config;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;

import org.vectrics.domain.Domain;


public class MailConfigurationImpl implements MailConfiguration {
	private String mailHost = null;
	private String mailPassword = null;
	private String mailUserName = null;
	private Domain domain = null;
	
	public MailConfigurationImpl(Domain domain) {
		super();
		this.domain = domain;
	}

	public Domain getDomain() {
		return(this.domain);
	}
	/*
	 * Returns mail session with configur
	 */
	public Session getMailSession() {
		Session session = null;
		Properties properties = System.getProperties();
		//properties.put("mail.host", this.getMailHost());
		//properties.put("mail.password", this.getMailPassword());
		//properties.put("mail.user", this.getMailUserName());
		properties.put("mail.smtp.auth", "true");
		properties.put("mail.smtp.host", this.getMailHost());
		//properties.put("mail.debug", true);
		//properties.put("mail.smtp.user", this.getMailUserName());
		//properties.put("mail.smtp.password", this.getMailPassword());
		session = Session.getDefaultInstance(properties, new Authenticator() {
			public PasswordAuthentication getPasswordAuthentication(){
				return new PasswordAuthentication(getMailUserName(),getMailPassword());
				} 
			});
		return(session);	
	}


	/**
	 * @return Returns the mailHost.
	 */
	public String getMailHost() {
		return mailHost;
	}

	/**
	 * @param mailHost The mailHost to set.
	 */
	public void setMailHost(String mailHost) {
		this.mailHost = mailHost;
	}

	/**
	 * @return Returns the mailPassword.
	 */
	public String getMailPassword() {
		return mailPassword;
	}

	/**
	 * @param mailPassword The mailPassword to set.
	 */
	public void setMailPassword(String mailPassword) {
		this.mailPassword = mailPassword;
	}

	/**
	 * @return Returns the mailUserName.
	 */
	public String getMailUserName() {
		return mailUserName;
	}

	/**
	 * @param mailUserName The mailUserName to set.
	 */
	public void setMailUserName(String mailUserName) {
		this.mailUserName = mailUserName;
	}
}
